package com.c.ctgproject.ui.files

import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.c.ctgproject.R
import com.c.ctgproject.adapter.file.FileVideoRecyclerViewAdapter
import com.c.ctgproject.adapter.service.ImageRecyclerViewAdapter
import com.c.ctgproject.base.BaseActivity
import com.c.ctgproject.entity.file.FileCarImageEntity
import com.c.ctgproject.entity.file.FileCarVideoEntity
import com.c.ctgproject.utils.*
import kotlinx.android.synthetic.main.activity_file_image_video.*

/**
 *作者:LiBW
 *创建日期: 2021/7/6
 *描述:档案部 图片 视频 页面
 */
class FileImageVideoActivity : BaseActivity() {
    private val mViewModel by lazy { ViewModelProvider(this)[FileImageVideoViewModel::class.java] }
    override fun getLayout() = R.layout.activity_file_image_video
    private val carId by lazy { intent.getStringExtra(MyConstants.CAR_ID).handlerNull() }
    override fun event() {

        mViewModel.getInPhoto(carId)
        mViewModel.getInVideo(carId)
        //视频
//        FileVideoRecyclerViewAdapter

        mViewModel.error.observe(this, {
            loading.dismiss()
            MyLog.d("错误:$it")
            showToast(it)
        })

        mViewModel.result.observe(this, {
            loading.dismiss()
            MyLog.d("车辆照片回调:$it")
            handlerHttpResult(it) {
                val data = getGson().fromJson(it, FileCarImageEntity::class.java).data
                //入场
                data?.entrancePicture?.let { list ->
                    mInRV.adapter = ImageRecyclerViewAdapter(this, list)
                    mInRV.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
                    if (list.isNotEmpty()) {
                        mInTV.visibility = View.GONE
                    }else{
                        mInRV.visibility = View.GONE
                    }
                }
                //拆解
                data?.dismantlePicture?.let { list ->
                    mDismantlingRV.adapter = ImageRecyclerViewAdapter(this, list)
                    mDismantlingRV.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
                    if (list.isNotEmpty()) {
                        mDismantlingTV.visibility = View.GONE
                    }else{
                        mDismantlingRV.visibility = View.GONE
                    }
                }
                //签名
                data?.procedurePicture?.let { list ->
                    mSignatureRV.adapter = ImageRecyclerViewAdapter(this, list)
                    mSignatureRV.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
                    if (list.isNotEmpty()) {
                        mSignatureTV.visibility = View.GONE
                    }else{
                        mSignatureRV.visibility = View.GONE
                    }
                }
            }
        })
        mViewModel.videoResult.observe(this, {
            loading.dismiss()
            MyLog.d("车辆视频:$it")
            handlerHttpResult(it) {
                val data = getGson().fromJson(it, FileCarVideoEntity::class.java).data
                data?.let {list->
                    mVideoRV.adapter = FileVideoRecyclerViewAdapter(this, list)
                    mVideoRV.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
                    if (list.isNotEmpty()) {
                        mVideoTV.visibility = View.GONE
                    }else{
                        mVideoRV.visibility = View.GONE
                    }
                }
            }
        })
    }

    override fun click() {

    }

}